home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Online / AmigaTalk / general / Block.st < prev    next >
Text File  |  2001-12-10  |  1KB  |  65 lines

  1. "---------------------------------------------------------------"
  2. "  Block Class.
  3.  
  4.    Note how whileTrue: and whileFalse: depend upon the parser
  5.    optimizing the loops into control flow, rather than message
  6.    passing.  If this were not the case, whileTrue: would have to
  7.    be implemented using recursion, as follows:
  8.  
  9.    whileTrue: aBlock
  10.       (self value)
  11.          ifFalse: [^nil].
  12.  
  13.       aBlock value.
  14.  
  15.       ^ self whileTrue: aBlock
  16. "
  17. "---------------------------------------------------------------"
  18.  
  19. Class Block :Object
  20. [
  21.    newProcess
  22.       ^ <primitive 141  self>
  23. |
  24.    newProcessWith: argumentArray
  25.       ^ <primitive 141  self argumentArray>
  26. |
  27.    fork
  28.       self newProcess resume.
  29.       ^ nil
  30. |
  31.    forkWith: argumentArray
  32.       (self newProcessWith: argumentArray) resume.
  33.       ^ nil
  34. |
  35.    whileTrue
  36.       ^ [self value ] whileTrue: []
  37. |
  38.    whileTrue: aBlock
  39.       ^ [ self value ] whileTrue: [ aBlock value ]
  40. |
  41.    whileFalse
  42.       ^ [ self value ] whileFalse: []
  43. |
  44.    whileFalse: aBlock
  45.       ^ [ self value ] whileFalse: [ aBlock value ]
  46. |
  47.    value
  48.       <primitive 140  0>
  49. |
  50.    value: a
  51.       <primitive 140  1>
  52. |
  53.    value: a value: b
  54.       <primitive 140  2>
  55. |
  56.    value: a value: b value: c
  57.       <primitive 140  3>
  58. |
  59.    value: a value: b value: c value: d
  60.       <primitive 140  4>
  61. |
  62.    value: a value: b value: c value: d value: e
  63.       <primitive 140  5>
  64. ]
  65.